package com.rui.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {


	public static Date str2Date(String dateStr, String format)
			throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.parse(dateStr);
	}


	public static String date2Str(Date date, String format)
			throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}

	public static void main(String[] args) throws ParseException {
		// String dateStr = "2017-03-18 00:00:00";
		String format = "yyyy-MM-dd HH:mm:ss";
		// Date date = DateUtil.str2Date(dateStr, format);
		// System.out.println(date.toLocaleString());
		String dateStr = DateUtil.date2Str(new Date(), format);
		System.out.println(dateStr);
	}
}